package cloud.watch.eurekaclient;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@SpringBootApplication
@EnableEurekaClient
@RestController
public class EurekaClientApplication {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private DiscoveryClient client;

    @GetMapping("/hello")
    public String index() {
        //List<ServiceInstance> instances = client.getInstances("");
        List<String> services = client.getServices();
        logger.info(services.toString());
        services.forEach(System.out::println);
        return "Hello World";
    }


    public static void main(String[] args) {
        SpringApplication.run(EurekaClientApplication.class, args);
    }
}
